﻿Imports System.Data.OleDb
Public Class Search
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SqlDataSource1.SelectCommand = "SELECT [ID], [Dabka_Name], [Dabka_Picture], [Dabka_Country], [Added time], [Added by], [Dabka_Ryhthm] " & _
                                  "FROM [Dabka] WHERE " & _
                                  " ( [Dabka_Country] like ""%" & Request.QueryString("word") & "%"" ) OR " & _
                                  " ( [Dabka_Ryhthm] like ""%" & Request.QueryString("word") & "%"" ) OR " & _
                                  " ( [Dabka_Name] like ""%" & Request.QueryString("word") & "%"" ) OR " & _
                                  " ( [Added by] like ""%" & Request.QueryString("word") & "%"" )  "

        GridView1.DataBind()


        If Request.QueryString("word") <> "" Then


            Dim searchby As String

            If User.Identity.Name <> "" Then
                searchby = User.Identity.Name
            Else
                searchby = "Anonymouse"
            End If



            Dim sql As String = "INSERT INTO SearchPhrases (S_Phrase, UserName) VALUES (@f1,@f2)"
            Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
            Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)

            cmd.Parameters.AddWithValue("@f1", Request.QueryString("word"))
            cmd.Parameters.AddWithValue("@f2", searchby)

            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
            cmd.Dispose()
            conn.Dispose()
        End If
    End Sub

    Protected Sub Btn_Search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_Search.Click
        Response.Redirect("~/Search.aspx?word=" & TB_Search.Text)
    End Sub
End Class